home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
A-B
/
add images.cpt
/
Source_2.c
< prev
next >
Wrap
Text File
|
1989-06-22
|
20KB
|
693 lines
/* ===================================
File: Source_2.c
Function: Handle all operations for this window
History: 4/27/89 Original by Prototyper.
================================= */
#include "Source_2.h"
#include "pix_io.h"
#include <ColorToolbox.h>
#include <IM5protos.h>
extern RGBColor BlackRGB, whiteRGB, grayRGB;
extern short pix_zoom;
extern short src_changed; /* 1 if pict scrolled or changed, 0 otherwise */
CGrafPtr flourine_bmap;
PicHandle flourine_pic; /* handle to PICT for source 1 */
Rect flourine_rect;
WindowPtr flourine_Window; /* Window pointer -- global variable */
short s2_off_top, s2_off_left; /* offsets on the window from scrolling */
static Str255 filename; /* local - image file, if any, associated with this window */
static void draw_flourine( void );
static void HandleVScrollBar (short code, short Start, short Stop,
short Increment, short LIncrement,
ControlHandle theControl, Point myPt);
static void HandleHScrollBar (short code, short Start, short Stop,
short Increment, short LIncrement,
ControlHandle theControl, Point myPt);
static void Do_A_ScrollBar (short code, ControlHandle theControl, Point myPt);
/* *********************************** */
/* These are the other includes for general routines */
#include "Strings.h"
extern char *strcpy (Str255 *, char *); /* LSC string prototype */
/* *********************************** */
#define TRUE 1
#define FALSE 0
#define NIL 0
/* *********************************** */
/* Scrollbar ID */
#define I_Horiz_Scroll_bar 27
/* Scrollbar ID */
#define I_Vert_Scroll_bar 26
static ControlHandle CtrlHandle; /* Control handle */
static ControlHandle ScrollHHandle, ScrollVHandle; /* Scrolling Control*/
static Str255 sTemp; /* Get text entered, temp holding */
static OSErr MyErr; /* General OS error return */
static ControlHandle C_Horiz_Scroll_bar; /* Scroll bar Control Handl*/
static ControlHandle C_Vert_Scroll_bar; /* Scroll bar Control Handle */
/* ====================================== */
/* Initialize us so all our routines can be activated */
void Init_flourine ()
{
flourine_Window = NIL; /* Make sure other routines know we are not */
flourine_rect.top = 0;
flourine_rect.bottom = all_my_colors;
flourine_rect.left = 0;
flourine_rect.right = 300;
}
/* ================================= */
void activate_flourine (whichWindow, modifiers)
WindowPtr whichWindow;
long modifiers;
{
WindowPtr SavePort;
GetPort (&SavePort);
if ( modifiers & activeFlag != 0 )
{
SelectWindow(whichWindow);
SetPort(whichWindow);
ShowControl (ScrollHHandle);
ShowControl (ScrollVHandle);
DrawGrowIcon( whichWindow );
DrawControls( whichWindow );
}
else
{
SetPort(whichWindow);
HideControl (ScrollHHandle);
HideControl (ScrollVHandle);
DrawGrowIcon( whichWindow );
DrawControls( whichWindow );
}
SetPort(SavePort);
}
typedef WStateData **WStateHandle;
void zoom_flourine( where, whichWindow, code )
Point *where;
WindowPeek whichWindow;
short code;
{
Point myPt;
WStateHandle WState;
SetPort (whichWindow);
if ( whichWindow->dataHandle != NIL )
{
WState = (WStateHandle) whichWindow->dataHandle;
(**WState).stdState = flourine_rect;
(**WState).stdState.top += 40;
(**WState).stdState.left += 2;
(**WState).stdState.right += 2;
(**WState).stdState.bottom += 40;
}
myPt = *where; /* Get mouse position */
GlobalToLocal (&myPt); /* Make it relative */
if (TrackBox (whichWindow, myPt, code) == TRUE)
{
EraseRect( &whichWindow->port.portRect );
ZoomWindow (whichWindow, code, TRUE);
InvalRect (&whichWindow->port.portRect);
}
Resized_flourine (flourine_Window);
}
void grow_flourine( where, whichWindow )
Point *where;
WindowPtr whichWindow;
{
Point myPt;
long mResult;
SetPort (whichWindow);
myPt = *where; /* Get mouse position */
GlobalToLocal (&myPt); /* Make it relative */
mResult = GrowWindow (whichWindow, *where, &flourine_rect);
SizeWindow (whichWindow, LoWord (mResult),
HiWord (mResult), TRUE);
Resized_flourine (flourine_Window);
}
/* We were resized or zoomed, update the scrolling scrollbars */
void Resized_flourine (whichWindow)/* Resized this window */
WindowPtr whichWindow; /* Window that was resized */
{
WindowPtr SavePort; /* Place to save the last port */
GetPort (&SavePort);
SetPort (flourine_Window);
if (ScrollHHandle != NIL)
{
HLock ((Handle)ScrollHHandle);
HideControl (ScrollHHandle);
InvalRect (&(*ScrollHHandle)->contrlRect); /* Flag old position for update rout*/
MoveControl (ScrollHHandle, flourine_Window->portRect.left-1,
flourine_Window->portRect.bottom - 15);
SizeControl (ScrollHHandle, (flourine_Window->portRect.right
- flourine_Window->portRect.left) - 13, 16);
ShowControl (ScrollHHandle);
HUnlock ((Handle)ScrollHHandle);
}
if (ScrollVHandle != NIL)
{
HLock ((Handle)ScrollVHandle);
HideControl (ScrollVHandle);
InvalRect (&(*ScrollVHandle)->contrlRect); /* Flag old position for update rout*/
MoveControl (ScrollVHandle, flourine_Window->portRect.right-15,
flourine_Window->portRect.top-1);
SizeControl (ScrollVHandle, 16, (flourine_Window->portRect.bottom
- flourine_Window->portRect.top) - 13);
ShowControl (ScrollVHandle);
HUnlock ((Handle)ScrollVHandle);
}
InvalRect(&flourine_Window->portRect);
DrawGrowIcon (flourine_Window);
SetPort (SavePort);
}
/* End of function */
/* ====================================== */
/* Update our window, someone uncovered a part of us */
void UpDate_flourine (whichWindow)
WindowPtr whichWindow;
{
WindowPtr SavePort; /* Place to save the last port */
GetPort (&SavePort); /* Save the current port */
SetPort (flourine_Window); /* Set the port to my window */
InvalRect(&flourine_Window->portRect);
BeginUpdate( flourine_Window );
draw_flourine();
DrawControls (flourine_Window); /* Draw all the controls */
DrawGrowIcon (flourine_Window); /* Draw the Grow box */
EndUpdate(flourine_Window);
SetPort (SavePort); /* Restore the old port */
}
static void draw_flourine()
{
Rect clipper;
Rect offrect; /* coords in offscreen bitmap */
short i;
clipper.top = flourine_Window->portRect.top;
clipper.bottom = flourine_Window->portRect.bottom - 15;
clipper.right = flourine_Window->portRect.right - 15;
clipper.left = flourine_Window->portRect.left;
ClipRect( &clipper );
EraseRect( &clipper );
if ( s2_off_top < flourine_rect.bottom &&
s2_off_left < flourine_rect.right )
{
if ( flourine_bmap != NIL )
{
offrect = clipper;
offrect.top += s2_off_top;
offrect.bottom += s2_off_top;
if ( offrect.bottom > flourine_rect.bottom + s2_off_top )
{
offrect.bottom = flourine_rect.bottom;
clipper.bottom = flourine_rect.bottom - s2_off_top;
}
offrect.left += s2_off_left;
offrect.right += s2_off_left;
if ( offrect.right > flourine_rect.right + s2_off_left )
{
offrect.right = flourine_rect.right;
clipper.right = flourine_rect.right - s2_off_left;
}
HLock((Handle) (flourine_bmap->portPixMap));
CopyBits( *(flourine_bmap->portPixMap), &thePort->portBits,
&offrect, &clipper, (short) srcCopy,
(RgnHandle) NIL);
HUnlock((Handle) (flourine_bmap->portPixMap));
}
else
{
SetOrigin( s2_off_left, s2_off_top );
for ( i = 0; i < all_my_colors; i++)
{
PmForeColor( i );
MoveTo( 0, i );
LineTo( 300, i );
}
SetOrigin( 0, 0);
}
}
ClipRect( &flourine_Window->portRect );
}
/* End of UpDate */
/* =========================================== */
/* vertical scroll bar */
static void HandleVScrollBar (code, Start, Stop, Increment, LIncrement,
theControl, myPt)
short code; /* Selection code for part of scroll bar */
short Start; /* Minimum value the scroll bar can assume */
short Stop; /* Maximum value the scroll bar can assume */
short LIncrement, Increment; /* Increment to move when pressed in an*/
ControlHandle theControl; /* Handle to the scroll bar control */
Point myPt; /* Returned point from track the scrollbar */
{ /* Start of this function */
short theValue; /* Value of the scrollbar */
long MaxTick; /* Timer used for repeat scrolling */
do /* Do the scroll as long as the button is do*/
{ /* Timer used for repeat scrolling */
HiliteControl (theControl, code); /* Darken the arrow */
theValue = GetCtlValue (theControl); /* Get current state */
if (code == inUpButton) /* See if in the Up arrow */
{
theValue = theValue - Increment; /* Subtract the single d*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the start value */
}
if (code == inDownButton) /* See if in the Down arrow */
{
theValue = theValue + Increment; /* Add the single decrem*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the stop value */
}
if (code == inPageUp) /* See if in the up/left grey area */
{
theValue = theValue - LIncrement; /* Subtract the page inc*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the Start value */
}
if (code == inPageDown) /* See if in the down/right grey area */
{
theValue = theValue + LIncrement; /* Add the page incremen*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the Stop value */
}
if (code == inThumb) /* See if in the drag box area */
{
code = TrackControl (theControl, myPt, NIL);
theValue = GetCtlValue (theControl);
}
SetCtlValue (theControl, theValue); /* Set new state */
s2_off_top = (short) ( (double)(flourine_rect.bottom - flourine_rect.top)
* (double) theValue / (double) (Stop - Start) );
draw_flourine();
MaxTick = TickCount () + 9; /* Time delay for auto-scroll */
do /* Start of delay routine */
{ /* Spin on doing nothing */
} while ((Button () == TRUE) && (TickCount () <= MaxTick)); /* E*/
HiliteControl (theControl, 0); /* Lighten the arrow */
} /* End for StillDown */
while (StillDown () == TRUE); /* End for StillDown */
}
/* End for HandleVScrollBar */
/* ====================================================== */
/* horizontal scroll bar */
static void HandleHScrollBar (code, Start, Stop, Increment, LIncrement,
theControl, myPt)
short code; /* Selection code for part of scroll bar */
short Start; /* Minimum value the scroll bar can assume */
short Stop; /* Maximum value the scroll bar can assume */
short LIncrement, Increment; /* Increment to move when pressed in an*/
ControlHandle theControl; /* Handle to the scroll bar control */
Point myPt; /* Returned point from track the scrollbar */
{ /* Start of this function */
short theValue; /* Value of the scrollbar */
long MaxTick; /* Timer used for repeat scrolling */
do /* Do the scroll as long as the button is do*/
{ /* Timer used for repeat scrolling */
HiliteControl (theControl, code); /* Darken the arrow */
theValue = GetCtlValue (theControl); /* Get current state */
if (code == inUpButton) /* See if in the Up arrow */
{
theValue = theValue - Increment; /* Subtract the single d*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the start value */
}
if (code == inDownButton) /* See if in the Down arrow */
{
theValue = theValue + Increment; /* Add the single decrem*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the stop value */
}
if (code == inPageUp) /* See if in the up/left grey area */
{
theValue = theValue - LIncrement; /* Subtract the page inc*/
if (theValue < Start) /* Check for boundary conditions */
theValue = Start; /* Pin at the Start value */
}
if (code == inPageDown) /* See if in the down/right grey area */
{
theValue = theValue + LIncrement; /* Add the page incremen*/
if (theValue > Stop) /* Check for boundary conditions */
theValue = Stop; /* Pin at the Stop value */
}
if (code == inThumb) /* See if in the drag box area */
{
code = TrackControl (theControl, myPt, NIL); /* Let the O*/
theValue = GetCtlValue (theControl); /* Get current state*/
}
SetCtlValue (theControl, theValue); /* Set new state */
s2_off_left = (short) ( (double)(flourine_rect.bottom - flourine_rect.top)
* (double) theValue / (double) (Stop - Start) );
draw_flourine();
MaxTick = TickCount () + 9; /* Time delay for auto-scroll */
do /* Start of delay routine */
{ /* Spin on doing nothing */
} while ((Button () == TRUE) && (TickCount () <= MaxTick)); /* E*/
HiliteControl (theControl, 0); /* Lighten the arrow */
} /* End for StillDown */
while (StillDown () == TRUE); /* End for StillDown */
}
/* End for HandleHScrollBar */
static void Do_A_ScrollBar (code, theControl, myPt) /* Handle a ScrollBa*/
short code; /* Which place in scrollbar was pressed */
ControlHandle theControl; /* Which place in scrollbar was pressed */
Point myPt; /* Where the scrollbar was pressed */
{ /* Start of a ScrollBar being pressed */
short RefCon;
RefCon = GetCRefCon (theControl); /* get control refcon */
switch (RefCon) /* Select correct scrollbar */
{
case I_Vert_Scroll_bar:
HandleVScrollBar (code, 1, 100, 1, 10, theControl, myPt);
src_changed = TRUE;
break;
case I_Horiz_Scroll_bar:
HandleHScrollBar (code, 1, 100, 1, 10, theControl, myPt);
src_changed = TRUE;
break;
default:
break;
} /* end of switch */
}
/* Handle a ScrollBar being pressed */
/* ================================= */
/* Open our window and draw everything */
void Open_flourine ()
{
Rect tempRect;
if (flourine_Window == NIL)
{
/* flourine_Window = (WindowPtr) GetNewCWindow (9, NIL, (WindowPtr) - 1); -- Get the w*/
tempRect.top = 139;
tempRect.bottom = 334;
tempRect.left = 201;
tempRect.right = 392;
flourine_Window = (WindowPtr) NewCWindow( (Ptr)NIL, &tempRect, "\pFlourine",
(Boolean) true, 8, (WindowPtr)-1, (Boolean)false, 9L);
/* MoveWindow (flourine_Window, tempRect.left, tempRect.top, TRUE); */
SetPort (flourine_Window);
/* Make a scroll bar, Vert Scroll bar */
ScrollVHandle = GetNewControl (I_Vert_Scroll_bar, flourine_Window);
/* Make a scroll bar, Horiz Scroll bar */
ScrollHHandle = GetNewControl (I_Horiz_Scroll_bar, flourine_Window);
ShowWindow (flourine_Window);
SelectWindow (flourine_Window);
/* SetPalette( flourine_Window, mypalette, true); */
/* RGBBackColor(&whiteRGB); */
/* RGBForeColor(&BlackRGB); -- copybits usually expect black fore and white back */
/* OpColor(&grayRGB); */
Resized_flourine (flourine_Window);
}
else
{
SelectWindow (flourine_Window); /* Already open, so show it */
}
}
/* End of open function */
/* ================================= */
/* Handle action to our window, like controls */
void Do_flourine (myEvent)
EventRecord *myEvent;
{
short RefCon; /* RefCon for controls */
short code; /* Location of event in window or controls */
short theValue; /* Current value of a control */
WindowPtr whichWindow;
Point myPt;
ControlHandle theControl;
WindowPtr SavePort;
/* Start of Window handler */
if (flourine_Window != NIL)
{
GetPort (&SavePort);
SetPort(flourine_Window);
SetOrigin(0, 0);
code = FindWindow (myEvent->where, &whichWindow);
if ((myEvent->what == mouseDown) && (flourine_Window == whichWindow))
{
myPt = myEvent->where; /* Get mouse position */
GlobalToLocal (&myPt); /* Make it relative */
}
if ((flourine_Window == whichWindow) && (code == inContent))
{
code = FindControl (myPt, whichWindow, &theControl);
if ((code == inUpButton) || (code == inDownButton)
|| (code == inThumb) || (code == inPageDown)
|| (code == inPageUp))
Do_A_ScrollBar (code, theControl, myPt);
if (code != 0) /* Check type of control */
code = TrackControl (theControl, myPt, NIL);
}
}
SetPort(SavePort);
}
/* End of function */
/* ================================= */
void read_flourine()
/* reads a PICT file and displays it in flourine window */
{
short width, height;
/*
put up open-file dialog
if not cancelled then
clear out current source_1 picture
open selected file
skip header 512 bytes
read to find out how big the picture is going to be, and then rewind a bit
allocate appropriate handle
read file into the handle
use the pict Frame in determining how big to create the pixmap for source1
create pixmap
copy the PICT into the pixmap
end if
*/
GDHandle theMaxDevice;
Point place;
Point tempP;
Rect globRect;
SFReply theReply;
SFTypeList theList;
short ix, iy;
place.h = 60;
place.v = 60;
theList[0] = 'PICT';
SFGetFile ( place, "\pOpen a GrayScale PICT file", NIL, 1, theList, NIL, &theReply );
SetPort( flourine_Window );
if ( theReply.good != 0 )
{
if ( flourine_pic != NIL )
{
DisposHandle( (Handle) flourine_pic );
}
if ( GetPic( theReply, &flourine_pic ) )
{
flourine_rect = (**flourine_pic).picFrame;
/* copy that PICT to our pixmap, converting it to use the Flourine colors */
height = flourine_rect.bottom - flourine_rect.top;
width = flourine_rect.right - flourine_rect.left;
flourine_rect.top = 0;
flourine_rect.bottom = height;
flourine_rect.left = 0;
flourine_rect.right = width;
tempP.v = flourine_Window->portRect.top;
tempP.h = flourine_Window->portRect.left;
LocalToGlobal(&tempP);
globRect.top = tempP.v;
globRect.left = tempP.h;
tempP.v = flourine_Window->portRect.bottom;
tempP.h = flourine_Window->portRect.right;
LocalToGlobal(&tempP);
globRect.bottom = tempP.v;
globRect.right = tempP.h;
theMaxDevice = GetMaxDevice(&globRect); /*get the maxDevice*/
flourine_bmap = pic_to_bmap( flourine_pic, &flourine_rect, theMaxDevice );
if ( flourine_bmap != NIL )
{
DisposHandle( flourine_pic );
}
src_changed = TRUE;
}
else /* failed to get a pict */
{
clear_flourine();
}
}
UpDate_flourine (flourine_Window);
}
void paste_flourine() /* !!! change this to use off screen bitmap */
/* paste a PICT from the clipboard and displays it in source_1 window */
{
short height, width, size;
long length, offset;
/*
look for PICT resource in clipboard
if there is a PICT then
clear out current source_1 picture
read to find out how big the picture is going to be, and then rewind a bit
allocate appropriate handle
read paste into the handle
use the pict Frame in determining how big to create the pixmap for source1
create pixmap
copy the PICT into the pixmap
end if
*/
flourine_pic = (PicHandle) NewHandle(0);
length = GetScrap( (Handle) flourine_pic, 'PICT', &offset);
if ( length > 0 )
{
flourine_rect = (**flourine_pic).picFrame;
width = flourine_rect.right - flourine_rect.left;
height = flourine_rect.bottom - flourine_rect.top;
size = width * height;
/* allocate offscreen-buffer based on size, etc.*/
flourine_rect.top = 0;
flourine_rect.left = 0;
flourine_rect.bottom = height;
flourine_rect.right = width;
}
UpDate_flourine (flourine_Window);
}
void clear_flourine() /* !!! change this to use off screen bitmap */
/* "cut" without clipboard */
{
if ( flourine_pic != NIL )
{
DisposHandle( (Handle) flourine_pic );
}
flourine_rect.top = 0;
flourine_rect.bottom = all_my_colors;
flourine_rect.left = 0;
flourine_rect.right = 300;
UpDate_flourine (flourine_Window);
}
void crop_flourine()
{
}